//
//  MineViewController.m
//  WHB_logist
//
//  Created by 徐国庆 on 15/12/7.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "MineViewController.h"
#import "AccountManagerViewController.h"
#import "QualificationCertificationViewController.h"
#import "AboutSystemViewController.h"

@interface MineViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(strong,nonatomic) User        *user;        //用户信息


@end

@implementation MineViewController

- (instancetype)initWithUser:(User *)user{
    self = [super init];
    if (self) {
        self.user = user;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navtitle.text = @"我的";
    [self initWithView];
    
}

#pragma mark UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //取得用户信息
    self.user = (User *)[NSKeyedUnarchiver unarchiveObjectWithFile:kUserPath];
    static NSString *indentifer = @"mineCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:indentifer];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 0) {
        if ([UtilsHelper isEmptyString:self.user.orgName]) {
            cell.textLabel.text = @"东长集团";
        } else{
            cell.textLabel.text = self.user.orgName;//@"东长集团";
        }
        cell.detailTextLabel.text = [NSString stringWithFormat:@"\n手机号:%@", self.user.telNum];//@"\n手机号:1372834463722";
        cell.detailTextLabel.numberOfLines = 0;
        cell.imageView.image = [UIImage imageNamed:@"tx_mr"];
        
        UIImageView *photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, -3, 50, 50)];
        photoImageView.backgroundColor = [UIColor redColor];
        photoImageView.layer.masksToBounds = YES;
        photoImageView.layer.cornerRadius = 25;
        [photoImageView sd_setImageWithURL:[NSURL URLWithString:self.user.userHeadPhoto] placeholderImage:[UIImage imageNamed:@"tx_mr"]];
        [cell.imageView addSubview:photoImageView];
        
    } else if (indexPath.row == 1){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:indentifer];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text = @"我的认证";
        cell.detailTextLabel.text = @"企业认证审核中";
    } else if (indexPath.row == 2){
        cell.textLabel.text = @"系统关于";
    }
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        AccountManagerViewController *accountManagerVC = [[AccountManagerViewController alloc] init];
        [self.navigationController pushViewController:accountManagerVC animated:YES];
    } else if (indexPath.row == 1){
        QualificationCertificationViewController *qualificationCertificationVC = [[QualificationCertificationViewController alloc] init];
        [self.navigationController pushViewController:qualificationCertificationVC animated:YES];
    } else if (indexPath.row == 2){
        NSLog(@"系统关于");
        AboutSystemViewController *aboutSystemVC = [[AboutSystemViewController alloc] init];
        [self.navigationController pushViewController:aboutSystemVC animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return 80;
    } else if (indexPath.row == 1 || indexPath.row == 2){
        return 50;
    }
    return 44;
}

- (void)initWithView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
